﻿using System;
using System.IO;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace RenderHeads.Media.AVProVideo.Demos
{
	// Token: 0x02000016 RID: 22
	public class VCR : MonoBehaviour
	{
		// Token: 0x17000007 RID: 7
		// (get) Token: 0x0600006B RID: 107 RVA: 0x00005208 File Offset: 0x00003408
		public MediaPlayer PlayingPlayer
		{
			get
			{
				if (this.LoadingPlayer == this._mediaPlayer)
				{
					return this._mediaPlayerB;
				}
				return this._mediaPlayer;
			}
		}

		// Token: 0x17000008 RID: 8
		// (get) Token: 0x0600006C RID: 108 RVA: 0x00005230 File Offset: 0x00003430
		public MediaPlayer LoadingPlayer
		{
			get
			{
				return this._loadingPlayer;
			}
		}

		// Token: 0x0600006D RID: 109 RVA: 0x00005238 File Offset: 0x00003438
		private void SwapPlayers()
		{
			this.PlayingPlayer.Control.Pause();
			if (this.LoadingPlayer == this._mediaPlayer)
			{
				this._loadingPlayer = this._mediaPlayerB;
			}
			else
			{
				this._loadingPlayer = this._mediaPlayer;
			}
			this._mediaDisplay.CurrentMediaPlayer = this.PlayingPlayer;
		}

		// Token: 0x0600006E RID: 110 RVA: 0x0000529C File Offset: 0x0000349C
		public void OnOpenVideoFile()
		{
			this.LoadingPlayer.m_VideoPath = Path.Combine(this._folder, this._videoFiles[this._VideoIndex]);
			this._VideoIndex = (this._VideoIndex + 1) % this._videoFiles.Length;
			if (string.IsNullOrEmpty(this.LoadingPlayer.m_VideoPath))
			{
				this.LoadingPlayer.CloseVideo();
				this._VideoIndex = 0;
			}
			else
			{
				this.LoadingPlayer.OpenVideoFromFile(this._location, this.LoadingPlayer.m_VideoPath, this._AutoStartToggle.isOn);
			}
		}

		// Token: 0x0600006F RID: 111 RVA: 0x00005338 File Offset: 0x00003538
		public void OnAutoStartChange()
		{
			if (this.PlayingPlayer && this._AutoStartToggle && this._AutoStartToggle.enabled && this.PlayingPlayer.m_AutoStart != this._AutoStartToggle.isOn)
			{
				this.PlayingPlayer.m_AutoStart = this._AutoStartToggle.isOn;
			}
			if (this.LoadingPlayer && this._AutoStartToggle && this._AutoStartToggle.enabled && this.LoadingPlayer.m_AutoStart != this._AutoStartToggle.isOn)
			{
				this.LoadingPlayer.m_AutoStart = this._AutoStartToggle.isOn;
			}
		}

		// Token: 0x06000070 RID: 112 RVA: 0x00005408 File Offset: 0x00003608
		public void OnMuteChange()
		{
			if (this.PlayingPlayer)
			{
				this.PlayingPlayer.Control.MuteAudio(this._MuteToggle.isOn);
			}
			if (this.LoadingPlayer)
			{
				this.LoadingPlayer.Control.MuteAudio(this._MuteToggle.isOn);
			}
		}

		// Token: 0x06000071 RID: 113 RVA: 0x0000546C File Offset: 0x0000366C
		public void OnPlayButton()
		{
			if (this.PlayingPlayer)
			{
				this.PlayingPlayer.Control.Play();
			}
		}

		// Token: 0x06000072 RID: 114 RVA: 0x00005490 File Offset: 0x00003690
		public void OnPauseButton()
		{
			if (this.PlayingPlayer)
			{
				this.PlayingPlayer.Control.Pause();
			}
		}

		// Token: 0x06000073 RID: 115 RVA: 0x000054B4 File Offset: 0x000036B4
		public void OnVideoSeekSlider()
		{
			if (this.PlayingPlayer && this._videoSeekSlider && this._videoSeekSlider.value != this._setVideoSeekSliderValue)
			{
				this.PlayingPlayer.Control.Seek(this._videoSeekSlider.value * this.PlayingPlayer.Info.GetDurationMs());
			}
		}

		// Token: 0x06000074 RID: 116 RVA: 0x00005524 File Offset: 0x00003724
		public void OnVideoSliderDown()
		{
			if (this.PlayingPlayer)
			{
				this._wasPlayingOnScrub = this.PlayingPlayer.Control.IsPlaying();
				if (this._wasPlayingOnScrub)
				{
					this.PlayingPlayer.Control.Pause();
				}
				this.OnVideoSeekSlider();
			}
		}

		// Token: 0x06000075 RID: 117 RVA: 0x00005578 File Offset: 0x00003778
		public void OnVideoSliderUp()
		{
			if (this.PlayingPlayer && this._wasPlayingOnScrub)
			{
				this.PlayingPlayer.Control.Play();
				this._wasPlayingOnScrub = false;
			}
		}

		// Token: 0x06000076 RID: 118 RVA: 0x000055AC File Offset: 0x000037AC
		public void OnAudioVolumeSlider()
		{
			if (this.PlayingPlayer && this._audioVolumeSlider && this._audioVolumeSlider.value != this._setAudioVolumeSliderValue)
			{
				this.PlayingPlayer.Control.SetVolume(this._audioVolumeSlider.value);
			}
			if (this.LoadingPlayer && this._audioVolumeSlider && this._audioVolumeSlider.value != this._setAudioVolumeSliderValue)
			{
				this.LoadingPlayer.Control.SetVolume(this._audioVolumeSlider.value);
			}
		}

		// Token: 0x06000077 RID: 119 RVA: 0x0000565C File Offset: 0x0000385C
		public void OnRewindButton()
		{
			if (this.PlayingPlayer)
			{
				this.PlayingPlayer.Control.Rewind();
			}
		}

		// Token: 0x06000078 RID: 120 RVA: 0x00005680 File Offset: 0x00003880
		private void Awake()
		{
			this._loadingPlayer = this._mediaPlayerB;
		}

		// Token: 0x06000079 RID: 121 RVA: 0x00005690 File Offset: 0x00003890
		private void Start()
		{
			if (this.PlayingPlayer)
			{
				this.PlayingPlayer.Events.AddListener(new UnityAction<MediaPlayer, MediaPlayerEvent.EventType, ErrorCode>(this.OnVideoEvent));
				if (this.LoadingPlayer)
				{
					this.LoadingPlayer.Events.AddListener(new UnityAction<MediaPlayer, MediaPlayerEvent.EventType, ErrorCode>(this.OnVideoEvent));
				}
				if (this._audioVolumeSlider && this.PlayingPlayer.Control != null)
				{
					float volume = this.PlayingPlayer.Control.GetVolume();
					this._setAudioVolumeSliderValue = volume;
					this._audioVolumeSlider.value = volume;
				}
				this._AutoStartToggle.isOn = this.PlayingPlayer.m_AutoStart;
				if (this.PlayingPlayer.m_AutoOpen)
				{
				}
				this.OnOpenVideoFile();
			}
		}

		// Token: 0x0600007A RID: 122 RVA: 0x0000576C File Offset: 0x0000396C
		private void Update()
		{
			if (this.PlayingPlayer && this.PlayingPlayer.Info != null && this.PlayingPlayer.Info.GetDurationMs() > 0f)
			{
				float currentTimeMs = this.PlayingPlayer.Control.GetCurrentTimeMs();
				float durationMs = this.PlayingPlayer.Info.GetDurationMs();
				float num = Mathf.Clamp(currentTimeMs / durationMs, 0f, 1f);
				this._setVideoSeekSliderValue = num;
				this._videoSeekSlider.value = num;
			}
		}

		// Token: 0x0600007B RID: 123 RVA: 0x000057FC File Offset: 0x000039FC
		public void OnVideoEvent(MediaPlayer mp, MediaPlayerEvent.EventType et, ErrorCode errorCode)
		{
			switch (et)
			{
			case MediaPlayerEvent.EventType.FirstFrameReady:
				this.SwapPlayers();
				break;
			}
			GlobalData.Debug_Log("Event: " + et.ToString());
		}

		// Token: 0x0400005E RID: 94
		public MediaPlayer _mediaPlayer;

		// Token: 0x0400005F RID: 95
		public MediaPlayer _mediaPlayerB;

		// Token: 0x04000060 RID: 96
		public DisplayUGUI _mediaDisplay;

		// Token: 0x04000061 RID: 97
		public Slider _videoSeekSlider;

		// Token: 0x04000062 RID: 98
		private float _setVideoSeekSliderValue;

		// Token: 0x04000063 RID: 99
		private bool _wasPlayingOnScrub;

		// Token: 0x04000064 RID: 100
		public Slider _audioVolumeSlider;

		// Token: 0x04000065 RID: 101
		private float _setAudioVolumeSliderValue;

		// Token: 0x04000066 RID: 102
		public Toggle _AutoStartToggle;

		// Token: 0x04000067 RID: 103
		public Toggle _MuteToggle;

		// Token: 0x04000068 RID: 104
		public MediaPlayer.FileLocation _location = MediaPlayer.FileLocation.RelativeToStreamingAssetsFolder;

		// Token: 0x04000069 RID: 105
		public string _folder = "AVProVideoDemos/";

		// Token: 0x0400006A RID: 106
		public string[] _videoFiles = new string[]
		{
			"BigBuckBunny_720p30.mp4",
			"SampleSphere.mp4"
		};

		// Token: 0x0400006B RID: 107
		private int _VideoIndex;

		// Token: 0x0400006C RID: 108
		private MediaPlayer _loadingPlayer;
	}
}
